package com.ticket.web.controller.yanchu;

import com.ticket.common.annotation.Log;
import com.ticket.common.core.controller.BaseController;
import com.ticket.common.core.domain.AjaxResult;
import com.ticket.common.core.page.TableDataInfo;
import com.ticket.common.enums.BusinessType;
import com.ticket.common.utils.poi.ExcelUtil;
import com.ticket.system.domain.YanchuTicketPrice;
import com.ticket.system.domain.vo.PriceVo;
import com.ticket.system.domain.vo.SeatDetailVo;
import com.ticket.system.domain.vo.SeatVo;
import com.ticket.system.domain.vo.TicketAndResVO;
import com.ticket.system.service.IYanchuTicketPriceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 场次价格Controller
 *
 * @author ruoyi
 * @date 2023-09-27
 */
@Api(description = "票档管理")
@RestController
@RequestMapping("/system/price")
public class YanchuTicketPriceController extends BaseController
{
    @Autowired
    private IYanchuTicketPriceService yanchuTicketPriceService;
    @ApiOperation("查询场次价格列表")
    @PreAuthorize("@ss.hasPermi('system:price:list')")
    @ApiImplicitParam(name = "sessionId",value = "演出id",required = true,dataType = "Long",dataTypeClass = Long.class)
    @GetMapping("/list")
    public TableDataInfo list(YanchuTicketPrice yanchuTicketPrice)
    {
        startPage();
        List<YanchuTicketPrice> list = yanchuTicketPriceService.selectYanchuTicketPriceList(yanchuTicketPrice);
        return getDataTable(list);
    }

    @ApiOperation("票档价格列表 （小程序售票端）")
    @ApiImplicitParam(name = "sessionId", value = "场次编码", dataType = "Long", dataTypeClass = Long.class)
    @GetMapping("/listPrice/forAllUser")
    public TableDataInfo listPrice(@RequestParam(name = "sessionId")Long sessionId)
    {
        List<PriceVo> list = yanchuTicketPriceService.selectTicketPriceVoList(sessionId);
        return getDataTable(list);
    }
    @ApiOperation("票档详情列表 去除已售出票（小程序售票端）")
    @ApiImplicitParam(name = "sessionId", value = "场次编码", dataType = "Long", dataTypeClass = Long.class)
    @GetMapping("/listPriceDetail/forAllUser")
    public TableDataInfo listPriceDetail(Long sessionId)
    {
        List<SeatDetailVo> list = yanchuTicketPriceService.selectSeatVoDetailList(sessionId);
        return getDataTable(list);
    }

    /**
     * 导出场次价格列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:export')")
    @Log(title = "场次价格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YanchuTicketPrice yanchuTicketPrice)
    {
        List<YanchuTicketPrice> list = yanchuTicketPriceService.selectYanchuTicketPriceList(yanchuTicketPrice);
        ExcelUtil<YanchuTicketPrice> util = new ExcelUtil<YanchuTicketPrice>(YanchuTicketPrice.class);
        util.exportExcel(response, list, "场次价格数据");
    }


    @ApiOperation("获取场次价格详细信息")
    @PreAuthorize("@ss.hasPermi('system:price:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(yanchuTicketPriceService.selectYanchuTicketPriceById(id));
    }

    @PreAuthorize("@ss.hasPermi('system:price:add')")
    @Log(title = "场次价格", businessType = BusinessType.INSERT)
    @ApiOperation("新增场次价格")
    @ApiImplicitParam(name = "yanchuTicketPrice", value = "场次价格对象", dataType = "YanchuTicketPrice", dataTypeClass = YanchuTicketPrice.class)
    @PostMapping
    public AjaxResult add(@RequestBody YanchuTicketPrice yanchuTicketPrice)
    {
        return toAjax(yanchuTicketPriceService.insertYanchuTicketPrice(yanchuTicketPrice));
    }

    @ApiOperation("修改场次价格(基础数据修改)")
    @PreAuthorize("@ss.hasPermi('system:price:edit')")
    @Log(title = "场次价格", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YanchuTicketPrice yanchuTicketPrice)
    {
        return toAjax(yanchuTicketPriceService.updateYanchuTicketPrice(yanchuTicketPrice));
    }

    @ApiOperation("删除场次价格")
    @PreAuthorize("@ss.hasPermi('system:price:remove')")
    @Log(title = "场次价格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Long id)
    {
        return toAjax(yanchuTicketPriceService.deleteYanchuTicketPriceById(id));
    }

    @ApiOperation("计算价格")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "seatVos", value = "座位列表", dataType = "List", dataTypeClass = List.class)
    })
    @Log(title = "计算价格", businessType = BusinessType.EXPORT)
    @PostMapping(value = "/calcPrice")
    public AjaxResult calcPrice(@RequestBody @Valid List<SeatVo> seatVos)
    {
        return yanchuTicketPriceService.calcPrice(seatVos);
    }

    @ApiOperation("处理票档价格座位及预留座座位处理")
    @ApiImplicitParam(name = "ticketAndResVO",value = "座位处理实体",dataType = "TicketAndResVO",dataTypeClass = TicketAndResVO.class)
    @PostMapping("/disposeTickAndRes")
    public AjaxResult disposeTickAndRes(@RequestBody List<TicketAndResVO> ticketAndResVOs){
        return toAjax(yanchuTicketPriceService.disposeTickAndRes(ticketAndResVOs));
    }
}
